﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FBGraph.ClientGenerator.CodeGen;

namespace FBGraph.ClientGenerator.Tests.CodeGen
{
    [TestClass]
    public class CodeGenObjectListTests
    {
        [TestMethod]
        public void WritesStringValues()
        {
            var list = new CodeGenObjectList<String>(null, "foo", "bar");

            var expected = "foobar";
            var actual = list.ToString();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void WritesStringValuesWithSeparator()
        {
            var list = new CodeGenObjectList<String>(", ", "foo", "bar");

            var expected = "foo, bar";
            var actual = list.ToString();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void WritesStringValuesWithLineBreaks()
        {
            var list = new CodeGenObjectList<String>(2, "foo", "bar");

            var expected =
@"foo

bar";
            var actual = list.ToString();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void WritesNonStringValues()
        {
            var list = new CodeGenObjectList<Int32>(null, 123, 456);

            var expected = "123456";
            var actual = list.ToString();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void WritesNonStringValuesWithSeparator()
        {
            var list = new CodeGenObjectList<Int32>(", ", 123, 456);

            var expected = "123, 456";
            var actual = list.ToString();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void WritesNonStringValuesWithLineBreaks()
        {
            var list = new CodeGenObjectList<Int32>(2, 123, 456);

            var expected =
@"123

456";
            var actual = list.ToString();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void WritesCodeGenObjects()
        {
            var list = new CodeGenObjectList<TestCodeGenObject>(new TestCodeGenObject("foo"), new TestCodeGenObject("bar"));

            var expected = "foobar";
            var actual = list.ToString();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void WritesCodeGenObjectsWithSeparator()
        {
            var list = new CodeGenObjectList<TestCodeGenObject>(", ", new TestCodeGenObject("foo"), new TestCodeGenObject("bar"));

            var expected = "foo, bar";
            var actual = list.ToString();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void WritesCodeGenObjectsWithLineBreaks()
        {
            var list = new CodeGenObjectList<TestCodeGenObject>(2, new TestCodeGenObject("foo"), new TestCodeGenObject("bar"));

            var expected =
@"foo

bar";
            var actual = list.ToString();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void EqualsComparesCorrectly()
        {
            // note: the item type must override Equals(Object), as TestCodeGenObject does, to do a value comparison intead of a reference comparison.
            var list1 = new CodeGenObjectList<TestCodeGenObject>(2, new TestCodeGenObject("foo"), new TestCodeGenObject("bar"));
            var list2 = new CodeGenObjectList<TestCodeGenObject>(2, new TestCodeGenObject("foo"), new TestCodeGenObject("bar"));

            Assert.IsTrue(list1.Equals(list2));
        }
    }
}